package com.woniuxy.banka.service.impl;

import com.woniuxy.banka.mapper.BankaMapper;
import com.woniuxy.banka.service.BankaService;
import com.woniuxy.common.entity.Bank;
import com.woniuxy.common.service.RemoteBankService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Author: 曾令忠
 * @Description:
 * @Date: 2020/7/11 0011-上午 10:52
 */
@Service
public class BankaServiceImpl implements BankaService {
    @Autowired(required = false)
    BankaMapper bankaMapper;
    @Autowired
    private RemoteBankService remoteBankService;

    @GlobalTransactional
    public void submoney(Bank bank) {
        //对方先加钱
        System.out.println("准备加钱");
        int res = remoteBankService.add();
        System.out.println(res);
        if(res>0){
            System.out.println(1/0);
            bankaMapper.submoney(bank);
        }
    }
}
